/*
  Small Game Library
  v 0.0
*/
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
#include <SDL_ttf.h>


#ifndef MIN
#define MIN(x,y)     (((x) < (y)) ? (x) : (y))
#define MAX(x,y)     (((x) > (y)) ? (x) : (y))
#define MID(x,y,z)   MAX((x), MIN((y), (z)))
#endif

#define SGL_COLORKEY 1
#define SGL_ALPHA 2

#define SGL_STOP 0
#define SGL_PLAY 1
#define SGL_LOOP 2


#define sgl_surface SDL_Surface
#define sgl_sound Mix_Chunk

extern Uint8 *sgl_keystate;
extern Uint8 sgl_lastkey;

extern int sgl_xmouse;
extern int sgl_ymouse;
extern int sgl_bmouse;

extern int sgl_volume;


//functions


//main-screen
sgl_surface *sgl_start( int w, int h, char *title) ; //start sgl initialize sdl and open the screen in window with title| return the screen surface
void sgl_terminate(); //stop sdl and terminate the program
void sgl_screenswap();//simulate the page swapping and update the events

void sgl_set_colorkey(Uint32 color); //set the color of trasparency
sgl_surface *sgl_surface_create(int w, int h, int option);//create an empty surface
sgl_surface *sgl_surface_load( char *filename, int option);//load an image like surface
void sgl_surface_destroy( sgl_surface *surface);//erase a surface
#define sgl_alpha(surface,level)    SDL_SetAlpha (surface, SDL_SRCALPHA, (Uint8) level)// set alpha level in a surface
void sgl_paste( sgl_surface *dst, int x, int y, sgl_surface *src);//blit a surface in another or in a screen
void sgl_blt( sgl_surface *dst, int x, int y, sgl_surface *src, int xs, int ys, int w, int h);//blit a part of surface in another
int sgl_hit(sgl_surface *surfacea, int xa, int ya, sgl_surface *surfaceb, int xb, int yb);// pixel precision surfaces collisions

// graphics
Uint32 sgl_rgb( int r, int g, int b);//return a color from rgb
void sgl_cls( sgl_surface *dst, Uint32 color); //clear all screen (needed after screen swap)

void sgl_plot( sgl_surface *surface, int x, int y, Uint32 color );//plot a pixel in surface
Uint32 sgl_point( sgl_surface *surface, int x, int y);//return the color of pixel in surface 0 if out of surface
void sgl_hline( sgl_surface * surface, int x1, int y1, int x2, Uint32 color);// draw a horizontal line
void sgl_vline( sgl_surface * surface, int x1, int y1, int y2, Uint32 color);// draw a vertical line
void sgl_line( sgl_surface * surface, int x1, int y1, int x2, int y2, Uint32 color);// draw a line
void sgl_box( sgl_surface *surface, int x, int y, int w, int h, Uint32 color);//draw a box
void sgl_bar( sgl_surface *surface, int x, int y, int w, int h, Uint32 color);//trace a fill rectangle
void sgl_circle( sgl_surface *surface, int vx, int vy, int r, Uint32 color);//draw a circle
void sgl_fillcircle( sgl_surface *surface, int vx, int vy, int r, Uint32 color);//draw a fill circle
void sgl_ellipse( sgl_surface *surface, int vx, int vy, int Xradius, int Yradius, Uint32 color);// draw an ellipse
void sgl_fillellipse( sgl_surface *surface, int vx, int vy, int Xradius, int Yradius, Uint32 color);//draw a fill ellipse
void sgl_paint(sgl_surface *surface, int vx, int vy, Uint32 color);// paint close area


//sounds & music
sgl_sound *sgl_sound_load( char *filename);//load a sound
void sgl_sound_play( sgl_sound *snd, int channel, int volume, int loop);//play a sound
void sgl_sound_destroy(sgl_sound *snd);//remove a sound loaded

void sgl_music_load( char *filename);//load a music
void sgl_music_play( int volume, int loop);//play a music | loop=0 stop 1=play 2=looping
int sgl_music_volume( int volume);//change the current music volume
//text
void sgl_setfont( char *fontPath);// set the current fontpath
sgl_surface *sgl_text( char *string, int size, Uint32 col);//make a text as surface
void sgl_print_text (sgl_surface *dst, int x,int y, int size, char *string,Uint32 col); //print a text in a surface


//input
#define sgl_mouse_show SDL_ShowCursor(1) //show the mouse cursor
#define sgl_mouse_hide SDL_ShowCursor(0) //hide the mouse cursor
#define sgl_mouse_set(x, y)  SDL_WarpMouse(x, y) //move the mouse at x,y screen position
